package com.mm.ai.controller;

import com.mm.ai.common.dto.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author： tzy
 * @Date： 2024/11/19 18:58
 */
@RestController
@RequestMapping("/wechat")
public class WeChatOauth2Controller {

    @GetMapping("/callback.do")
    public ResponseEntity<String> handleWechatCallback(
            @RequestParam(value = "code", required = false) String code,
            @RequestParam(value = "state", required = false) String state) {

        String r = null;
        // 处理微信回调逻辑
        if (code != null) {
            // 通过code获取access_token和openid
            // 调用微信API获取用户信息
            // 保存用户信息到数据库等操作
            r = "Callback received with code: " + code + " and state: " + state;
        } else {
            r = "No code provided in the callback";
        }
       return ResponseEntity.ok(r);
    }
}
